#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
ll n, k;
const ll N = 3e5 + 10;
ll a[N];
bool check(ll x)
{
    ll res = 0;
    for (ll i = 1; i <= n; i++)
    {
        if (a[i] >= x)
        {
            res = res + a[i] - x + 1;
        }
    }
    return res >= k;
}
void solve()
{
    cin >> n >> k;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    ll l = 1, r = 1e9, ans;
    while (l <= r)
    {
        ll mid = l + (r - l) / 2;
        if (check(mid))
        {
            l = mid + 1, ans = l;
        }
        else
        {
            r = mid - 1;
        }
    }
    // cout << ans;
    ll cnt = 0;
    for (ll i = 1; i <= n; i++)
    {
        if (a[i] >= ans)
        {
            ll nn = (a[i] - ans + 1);
            // cout << nn << endl;
            cnt = cnt + (nn * ans + (nn * (nn - 1)) / 2);
            k -= nn;
        }
    }
    // cout << k << ":";
    cnt += k * (ans-1);
    cout << cnt << "\n";
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        // cout << (4 - 1) *4 - (4 - 1) * (4 - 2) / 2;
        solve();
    }
    return 0;
}
